package com.favorite;

public class Solution337 {
    public int rob(TreeNode root) {
        int[] ints = robAct(root);
        return Math.max(ints[0], ints[1]);
    }

    public int[] robAct(TreeNode root) {
        if (root == null) return new int[]{0, 0};
        int[] left = robAct(root.left);
        int[] right = robAct(root.right);
        int[] res = new int[2];
        res[0] = root.val + left[1] + right[1];
        res[1] = Math.max(left[0], left[1]) + Math.max(right[0], right[1]);
        return res;
    }
}
